package com.nidu.demo.file.model;

import com.alibaba.cola.exception.BizException;
import com.nidu.demo.base.BaseDeletableEntity;
import com.nidu.demo.base.BaseTenantEntity;
import com.nidu.demo.common.enums.BooleanEnum;
import com.nidu.demo.common.exception.ErrorCodeConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Map;

/**
 * 文件配置领域实体
 *
 * @author auto
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class FileConfig extends BaseTenantEntity implements BaseDeletableEntity {

    private Long id;

    /**
     * 配置名
     */
    private String name;

    /**
     * 存储器类型
     */
    private Integer storage;

    /**
     * 是否为主配置
     */
    private Boolean master;

    /**
     * 存储配置参数
     */
    private Map<String, Object> config;

    /**
     * 备注
     */
    private String remark;

    /**
     * 是否删除
     */
    private Boolean deleted;

    @Override
    public void isDeleted() {
        if (BooleanEnum.TRUE.getValue().equals(this.getDeleted())) {
            throw new BizException(ErrorCodeConstants.FILE_CONFIG_NOT_FOUND.getCode(), ErrorCodeConstants.FILE_CONFIG_NOT_FOUND.getMessage());
        }
    }

    public static FileConfig create(String name, Integer storage,  Map<String, Object> config, String remark) {
        FileConfig fileConfig = new FileConfig();
        fileConfig.setName(name)
                .setStorage(storage)
                .setConfig(config)
                .setRemark(remark);
        return fileConfig;
    }

    public static FileConfig update(Long id, String name, Integer storage, Map<String, Object> config, String remark) {
        FileConfig fileConfig = new FileConfig();
        fileConfig.setId(id)
                .setName(name)
                .setStorage(storage)
                .setConfig(config)
                .setRemark(remark);
        return fileConfig;
    }
}
